package com.lg.mengbase.main;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import com.lg.baselibrary.activity.BaseToolbarActivity;
import com.lg.baselibrary.activity.IActivity;
import com.lg.baselibrary.adapter.BaseRecyclerViewAdapter;
import com.lg.baselibrary.adapter.BaseRecyclerViewHolder;
import com.lg.baselibrary.adapter.BaseViewHolder;
import com.lg.baselibrary.widget.BaseRecyclerView;
import com.lg.mengbase.R;
import com.lg.mengbase.TestKeyboardListenerAty;
import com.lg.mengbase.demo.TestRegistUiActivity;
import com.lg.mengbase.testBaseRecyclerAdapter.activity.TestBaseRecyclerAdapterActivity;
import com.lg.mengbase.testBaseRecyclerAdapter.activity.TestMoreLayoutRecyclerViewActivity;
import com.lg.mengbase.testBottonTab.TestBottomTabViewActivity;
import com.lg.mengbase.testBottonTab.TestBottomTabViewActivity2;
import com.lg.mengbase.testBottonTab.TestBottomTabViewPagerActivity;
import com.lg.mengbase.testBottonTab.TestBottomTabViewPagerActivity2;
import com.lg.mengbase.testlistview.TestBaseListViewAdapterActivity;
import com.lg.mengbase.testlistview.TestMoreLayoutListViewActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseToolbarActivity implements BaseRecyclerViewHolder.OnItemClickListener,IActivity {

    @BindView(R.id.recyclerView)
    BaseRecyclerView recyclerView;
    private MainAdapter adapter;

    @Override
    public int provideContentViewLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        adapter = new MainAdapter(this);
        adapter.setDatas(getDatas());
        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);
    }

    private List<Item> getDatas() {
        List<Item> list = new ArrayList<>();
        list.add(new Item("测试BaseRecyclerViewAdapter(没有头脚)", TestBaseRecyclerAdapterActivity.class));
        list.add(new Item("测试BaseRecyclerViewAdapter(多item布局)", TestMoreLayoutRecyclerViewActivity.class));
        list.add(new Item("测试BaseAbsListViewAdapter(没有头脚)", TestBaseListViewAdapterActivity.class));
        list.add(new Item("测试BaseListViewAdapter(多item布局)", TestMoreLayoutListViewActivity.class));
        list.add(new Item("Tabs+ViewPager+Fragment", TestBottomTabViewPagerActivity.class));
        list.add(new Item("Tabs+ViewPager+Fragment(CenterView)", TestBottomTabViewPagerActivity2.class));
        list.add(new Item("Tabs+FrameLayout+Fragment(CenterView)", TestBottomTabViewActivity.class));
//        list.add(new Item("Bug测试", App.class));
        list.add(new Item("测试键盘显示和隐藏的监听", TestKeyboardListenerAty.class));
        list.add(new Item("仿亲爱的app底部tabs(点击有动画)",TestBottomTabViewActivity2.class));
        list.add(new Item("仿为知笔记app注册界面效果",TestRegistUiActivity.class));
        return list;
    }

    @Override
    public void onItemClick(BaseViewHolder holder, ViewGroup parent,View itemView, int position) {
//        startActivity(adapter.getItem(position).clazz);
        startActivity(new Intent(this,adapter.getItem(position).clazz));
    }

    @Override
    protected void initTitle() {
        setToolbarTitle("功能测试列表");

    }

    class Item {
        String title;
        Class<?> clazz;

        public Item(String title, Class<?> clazz) {
            this.title = title;
            this.clazz = clazz;
        }
    }
    class MainAdapter extends BaseRecyclerViewAdapter<Item>{

        public MainAdapter(Context context) {
            super(context);
        }

        @Override
        protected int getItemViewLayout(int position) {
            return android.R.layout.simple_list_item_1;
        }

        @Override
        public void convert(BaseViewHolder viewHolder, Item item, int position) {
            viewHolder.setText(android.R.id.text1,item.title);
        }
    }
}
